package cc.fs.study.rxjava;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import cc.fs.study.R;
import cc.fs.study.rxjava.util.RxBus;
import cc.fs.study.widget.AvatarImageView;
import rx.Subscriber;

public class RxjavaActivity extends AppCompatActivity {

    TextView btn1,btn2;
    AvatarImageView avatarImageView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rxjava);

        btn1 = (Button) findViewById(R.id.btn1);
        btn2 = (Button) findViewById(R.id.btn2);
        avatarImageView = (AvatarImageView) findViewById(R.id.vipImageView);

        btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                avatarImageView.setIsAuth(true);

//                Intent intent = new Intent(RxjavaActivity.this,RxjavaActivity2.class);
//                startActivity(intent);
//                finish();
            }
        });

        btn2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                avatarImageView.setIsAuth(false);
            }
        });

        RxBus.Builder().subscribe(Message1.class, new Subscriber<Message1>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onNext(Message1 message1) {
                Log.e("----","数据返回了 消息1");

            }

        });

        RxBus.Builder().subscribe(Message2.class, new Subscriber<Message2>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onNext(Message2 o) {
                Log.e("----","RxjavaActivity1数据返回了 消息2");
            }
        });

    }
}
